package com.sunsharing.container;

import com.sunsharing.common.anno.AnoClassCretator;
import com.sunsharing.common.anno.AnoClassCretator;
import com.sunsharing.common.config.Config;
import com.sunsharing.container.command.Command;
import com.sunsharing.container.command.Statistics;
import com.sunsharing.container.command.Worker;
import com.sunsharing.flow.exe.WorkFlowService;
import com.sunsharing.flow.model.ProcessDefinition;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * User: criss
 * Date: 13-4-8
 * Time: 下午8:15
 * To change this template use File | Settings | File Templates.
 */
public class Main {

    public static void main(String []a)
    {

        AnoClassCretator.getInstance().loadAllClasses();
        //初始化配置文件
        Config.getInstance();
        if(a!=null)
        {
            Config.getInstance().setNodeId(a[0]);
        }
        //初始化流程报文
        WorkFlowService.loadFlows();
        //初始化监听服务器
        ServerCreater.initServer();

        //处理关闭事件
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {

                System.out.println("Stop");
                ServerCreater.stopServer();

            }
        });



        //命令循环
        while(true)
        {
            BufferedReader stdin =new BufferedReader(new InputStreamReader(System.in));

            Worker w = new Worker();
            Command sta = new Statistics(w);

            System.out.print("Enter a Command(--help):");
            try
            {
                String line = stdin.readLine();
                if(line.equals("help"))
                {
                    System.out.println("sta -> 显示状态");
                }else if(line.equals("sta"))
                {
                    sta.run();
                }
                else
                {
                    System.out.println("Error command line");
                }

            }catch (Exception e)
            {

            }
        }


    }

}
